<?php use_helper('JQuery') ?>

<div id="main_header" class="ui-widget-header ui-corner-all">
    <h3>
        Lista de comentarios
    </h3>
</div>
<?php if(!$pager->getResults()->count()):?>
    <div id="main_content" class="ui-widget ui-widget-content ui-corner-all">
        <div style="text-align: center; margin: 5em 1em 1em 1em;">
            <h4><b><p>No se han encontrado comentarios sobre este contenido.</b></h4>
        </div>
    </div>
<?php else: ?>
    <div id="main_content" class="ui-widget ui-widget-content ui-corner-all">
        <div id="form">
            <?php echo jq_form_remote_tag(
                array (
                    'update' => 'main',
                    'url'    => url_for('content_comments_approval',$content).'?page='.$pager->getPage().'&next='.$pager->getNextPage(),
                    'script' => true
                    )
                )?>
                <input type="hidden" name="sf_method" value="put" />
                <div>
                    <?php echo $form->renderHiddenFields() ?>
                    <?php echo $form->renderGlobalErrors() ?>
                    <div class="form-field">

                    </div>
                </div>
                <table id="comments">
                    <tr>
                        <th>Sección</th>
                        <th>Contenido</th>
                        <th>Comentario</th>
                        <th>Aprobar</th>
                        <th>Eliminar</th>
                        <th>Fecha de creación</th>
                    </tr>
                    <?php foreach ($pager->getResults() as $i=>$comment): ?>
                        <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>" >
                            <td><?php echo $comment->getContent()->getSection()?></td>
                            <td><?php echo $comment->getContent()?></td>
                            <td><?php echo $comment->getComment()?></td>
                            <td><?php echo $form['comments'][$i]['approved']->render() ?><?php echo $form['comments'][$i]['approved']->renderError() ?></td>
                            <td><?php echo $form['comments'][$i]['is_enabled']->render() ?><?php echo $form['comments'][$i]['is_enabled']->renderError() ?></td>
                            <td><?php echo $comment->getDateTimeObject('created_at')->format('d/m/Y - g:i a') ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
                <div id="form_buttons" class="ui-widget">
                    <div>
                        <input class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-button-text"
                               type="submit" value="Guardar modificaciones" title="Guardar modificaciones"/>
                    </div>
                </div>
            </form>
        </div>
        <div class="pagination-desc">
            <strong><?php echo count($pager) ?></strong> comentarios
            <?php if ($pager->haveToPaginate()): ?>
                - pagina <strong><?php echo $pager->getPage() ?>/<?php echo $pager->getLastPage() ?></strong>
            <?php endif; ?>
        </div>
        <?php if ($pager->haveToPaginate()): ?>
            <div class="pagination">
                <?php echo jq_link_to_remote(
                    '<span class="ui-button-icon-primary ui-icon ui-icon-seek-first"></span>
                    <span class="ui-button-text">Inicio</span>',
                    array(
                        'update' => 'main',
                        'url'    => url_for('content_comments',$content).'?page=1',
                        'after'  => 'clearView();'
                    ),
                    array(
                        'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only',
                        'title' => '1ra página.',
                        'alt'   => '1ra página.'
                    ))?>
                <?php echo jq_link_to_remote(
                    '<span class="ui-button-icon-primary ui-icon ui-icon-seek-prev"></span>
                    <span class="ui-button-text">Anterior</span>',
                    array(
                        'update' => 'main',
                        'url'    => url_for('content_comments',$content).'?page='.$pager->getPreviousPage(),
                        'after'  => 'clearView();'
                    ),
                    array(
                        'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only',
                        'title' => 'Página '.$pager->getPreviousPage(),
                        'alt'   => 'Página '.$pager->getPreviousPage()
                    ))?>
                <?php foreach ($pager->getLinks() as $page): ?>
                    <?php if ($page == $pager->getPage()): ?>
                        <strong><?php echo $page ?></strong>
                    <?php else: ?>
                        <?php echo jq_link_to_remote(
                            '<span class="ui-button-text">'.$page.'</span>',
                            array(
                                'update' => 'main',
                                'url'    => url_for('content_comments',$content).'?page='.$page,
                                'after'  => 'clearView();'
                            ),
                            array(
                                'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                                'title' => 'Página '.$page,
                                'alt'   => 'Página '.$page
                            ))?>
                    <?php endif; ?>
                <?php endforeach; ?>
                <?php echo jq_link_to_remote(
                    '<span class="ui-button-icon-primary ui-icon ui-icon-seek-next"></span>
                    <span class="ui-button-text">Siguiente</span>',
                    array(
                        'update' => 'main',
                        'url'    => url_for('content_comments',$content).'?page='.$pager->getNextPage(),
                        'after'  => 'clearView();'
                    ),
                    array(
                        'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only',
                        'title' => 'Página '.$pager->getNextPage(),
                        'alt'   => 'Página '.$pager->getNextPage()
                    ))?>
                <?php echo jq_link_to_remote(
                    '<span class="ui-button-icon-primary ui-icon ui-icon-seek-end"></span>
                    <span class="ui-button-text">Fin</span>',
                    array(
                        'update' => 'main',
                        'url'    => url_for('content_comments',$content).'?page='.$pager->getLastPage(),
                        'after'  => 'clearView();'
                    ),
                    array(
                        'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only',
                        'title' => 'Última página',
                        'alt'   => 'Última página'
                    ))?>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>
